package de.hs_heilbronn;


public class Stud {

	private int matrikel;
	private String vorname;
	private String nachname;
	private Database db = new Database();
	
	public Stud(){
		
	}
	
	public Stud (int matrikel, String vorname, String nachname){
		this.matrikel = matrikel;
		this.vorname = vorname;
		this.nachname = nachname;
	}
		
	public String toString(){
		return Integer.toString(matrikel);
	}
	
	public void setVorname(String vorname) {
		this.vorname = vorname;
		db.connectUpdate("UPDATE student SET vorname='" + this.vorname + "', nachname='" + this.nachname + "' WHERE id=" + this.matrikel + ";");
	}

	public void setNachname(String nachname) {
		this.nachname = nachname;
		db.connectUpdate("UPDATE student SET vorname='" + this.vorname + "', nachname='" + this.nachname + "' WHERE id=" + this.matrikel + ";");
	}

	public void setDb(Database db) {
		this.db = db;
	}

	public void setMatrikel(int matrikel) {
		this.matrikel = matrikel;
	}
	
	public int getMatrikel() {
		return matrikel;
	}

	public String getVorname() {
		return vorname;
	}

	public String getNachname() {
		return nachname;
	}

	public Database getDb() {
		return db;
	}

	public String delete(){
		db.connectUpdate("DELETE FROM student WHERE id=" + this.matrikel + ";");
		return "success";
	}
	
}

